#ifndef ESP8266_H
#define ESP8266_H

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "delay.h"
#include "at_client.h"

#define ESP8266_WIFI_SSID       "esp8266"
#define ESP8266_WIFI_PASSWORD   "12345678"


#define SOCKET_MAX_NUM                 5
#define ESP8266_MODULE_SEND_MAX_SIZE   2048
#define ESP8266_MODULE_RECIVE_MAX_SIZE 512

enum at_socket_state
{
    AT_SOCKET_NONE,
    AT_SOCKET_OPEN,
    AT_SOCKET_LISTEN,
    AT_SOCKET_CONNECT,
    AT_SOCKET_CLOSED
};

struct at_socket{
    enum at_socket_state state;
    char clientIp[16];
    char clientMac[32];
    char buf[ESP8266_MODULE_RECIVE_MAX_SIZE];
    int bufLen;
};

void esp8266_init(int port);
int at_listen(void);
int at_recv(int socket,void *mem, size_t len);
int at_send(int socket, const char *buff, size_t bfsz);
int at_close(int socket);

#endif
